package com.example.servletdemo.listner;

import com.example.servletdemo.utils.DateUtils;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;

//网站浏览量记录
//@WebListener
public class MyServletRequestListener implements ServletRequestListener {
    private static final String TAG = "MyHttpSessionLister=>";
    @Override
    public void requestDestroyed(ServletRequestEvent arg0) {
        System.out.println(TAG+"requestDestroyed=>"+"当前访问次数：" + arg0.getServletContext().getAttribute("count"));
    }

    @Override
    public void requestInitialized(ServletRequestEvent arg0) {
        Object count = arg0.getServletContext().getAttribute("count");
        Integer his_count = 0;
        if (count != null) {
            his_count = Integer.valueOf(count.toString());
            System.out.println(TAG+"requestInitialized===================>" +"历史访问次数：：" + count);
        }
        his_count++;
        arg0.getServletContext().setAttribute("count",his_count );
    }
}
